# Maintainer: David Runge <dvzrv@archlinux.org>

_name=igbinary
pkgbase=php-igbinary
pkgname=(php-igbinary php-legacy-igbinary)
pkgver=3.2.14
pkgrel=2
pkgdesc="A drop in replacement for the standard php serializer"
arch=(loong64 x86_64)
url="https://github.com/igbinary/igbinary"
license=(BSD)
depends=(glibc)
makedepends=(php-legacy php)
source=($pkgname-$pkgver.tar.gz::https://github.com/$_name/$_name/archive/$pkgver.tar.gz)
sha512sums=('8f58817b86c560bd81344ec51260d31b02868584254d6b94b44e07ea5371ddebfc2ccee7bc56ca1ad5873bdbb758fc95683555e7c5abf5d69db9d962bf0e88b3')
b2sums=('17cb77a68e2458021563ae288fccbd49132b04f9b5e2a27b7dbfc2c851536d30b813fcf4cc48684afda0cd3e3b0c2c915b13b668d85715d827bee86a4c499573')

prepare() {
  mv -v $_name-$pkgver $pkgbase-$pkgver
  # disable the extension by default
  sed 's/extension/;extension/g' -i $pkgbase-$pkgver/$_name.php.ini

  cp -av $pkgbase-$pkgver ${pkgname[1]}-$pkgver
  (
    cd $pkgbase-$pkgver
    phpize
  )
  (
    cd ${pkgname[1]}-$pkgver
    phpize-legacy
  )
}

build() {
  (
    cd $pkgbase-$pkgver
    ./configure --prefix=/usr \
                --enable-igbinary
    make
  )
  (
    cd ${pkgname[1]}-$pkgver
    ./configure --prefix=/usr \
                --enable-igbinary
    make
  )
}

check() {
  (
    NO_INTERACTION=1 make -k test -C $pkgbase-$pkgver
  )
  (
    NO_INTERACTION=1 make -k test -C ${pkgname[1]}-$pkgver
  )
}

package_php-igbinary() {
  local _interpreter_version="$(php --version |head -n1 |cut -d ' ' -f2)"

  depends+=(php)
  _provides=(php-igbinary-interpreter=${_interpreter_version%.*})
  provides=("${_provides[@]}")
  backup=(etc/php/conf.d/$_name.ini)

  cd $pkgname-$pkgver
  make INSTALL_ROOT="$pkgdir" install
  install -vDm 644 $_name.php.ini "$pkgdir/etc/php/conf.d/$_name.ini"
  install -vDm 644 COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 {CREDITS,NEWS,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}

package_php-legacy-igbinary() {
  local _interpreter_version="$(php-legacy --version |head -n1 |cut -d ' ' -f2)"

  depends+=(php-legacy)
  _provides=(php-igbinary=$pkgver php-igbinary-interpreter=${_interpreter_version%.*})
  provides=("${_provides[@]}")
  backup=(etc/php-legacy/conf.d/$_name.ini)

  cd $pkgname-$pkgver
  make INSTALL_ROOT="$pkgdir" install
  install -vDm 644 "$_name.php.ini" "$pkgdir/etc/php-legacy/conf.d/$_name.ini"
  install -vDm 644 COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 {CREDITS,NEWS,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}
